package com.wythe.mall.adapter;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.wythe.mall.R;
import com.wythe.mall.activity.GoodsActivity;
import com.wythe.mall.model.RecommentBean;
import com.wythe.mall.model.ShopBean;
import com.wythe.mall.utils.DPIUtil;
import com.wythe.mall.utils.DensityUtils;
import com.wythe.mall.utils.GotoActivity;
import com.wythe.mall.utils.StringUtils;
import com.wythe.mall.utils.TimeUtil;
import com.wythe.mall.view.NoScrollGridView;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 图片适配器
 * Created by Yancy on 2015/12/2.
 */
public class EvaluateGoodsAdapter extends BaseAdapter implements RecommentImgAdapter.OnImagesChangedCallback {

    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private List<RecommentBean> imageList;
    private final static String TAG = "ImageAdapter";

    private static final int TYPE_CAMERA = 0;
    private static final int TYPE_NORMAL = 1;

    private boolean showCamera = true;
    private int mItemSize;
    private int screenWidth;
    public EvaluateGoodsAdapter(Context context, List<RecommentBean> imageList) {
        mLayoutInflater = LayoutInflater.from(context);
        mContext = context;
        this.imageList = imageList;
        screenWidth = DensityUtils.screenWidth(context);
    }

    @Override
    public int getCount() {
        return imageList.size();
    }

    @Override
    public Object getItem(int position) {
        return imageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        RecommentBean recommentBean = imageList.get(position);
        ViewHolder holder;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.item_goods_evaluate, parent, false);
            holder = new ViewHolder(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Glide.with(mContext)
                .load(recommentBean.getTsmUserVo().getAvatarurl())
                .dontAnimate()
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(holder.mHeadImg);

        holder.tvTime.setText(TimeUtil.msToDate(recommentBean.getTimeStamp(), "yyyy-MM-dd HH:mm:ss"));
        holder.mName.setText(recommentBean.getTsmUserVo().getNickname());
        holder.tvDes.setText((recommentBean.getCommentInfo().length() > 0 ? recommentBean.getCommentInfo() : "暂无评论！！！"));
        RecommentImgAdapter imgAdapter = new RecommentImgAdapter(mContext,this);
        holder.mGridView.setAdapter(imgAdapter);
        imgAdapter.setImages(recommentBean.getImgUrl());
        return convertView;
    }

    @Override
    public void onImagesChanged() {

    }

    class ViewHolder {
        CircleImageView mHeadImg;
        TextView mName;
        TextView tvDes;
        TextView tvTime;
        TextView tvEvaluate;
        NoScrollGridView mGridView;

        ViewHolder(View itemView) {
            mHeadImg = itemView.findViewById(R.id.user_img_view);
            mName = itemView.findViewById(R.id.tv_name);
            tvDes = itemView.findViewById(R.id.tv_des);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvEvaluate = itemView.findViewById(R.id.tv_evaluate);
            mGridView = itemView.findViewById(R.id.grid_image);
            itemView.setTag(this);
        }

    }


    @Override
    public int getItemViewType(int position) {
        return TYPE_NORMAL;
    }
}